<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      ref="queryFormRef"
      :inline="true"
      :model="queryParams"
      class="-mb-15px"
      label-width="68px"
    >
      <el-form-item label="门店类型" prop="groupId">
        <el-select v-model="groupId" placeholder="请选择门店类型" clearable class="!w-280px">
          <el-option v-for="group in []" :key="group.id" :label="group.name" :value="group.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="门店名称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          class="!w-280px"
          clearable
          placeholder="请输入门店名称"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户编号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          class="!w-280px"
          clearable
          placeholder="请输入商户编号"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          class="!w-280px"
          clearable
          placeholder="请输入设备编号"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="groupId">
        <el-select
          v-model="queryParams.groupId"
          placeholder="请选择支付方式"
          clearable
          class="!w-280px"
        >
          <el-option v-for="group in []" :key="group.id" :label="group.name" :value="group.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="交易状态" prop="groupId">
        <el-select
          v-model="queryParams.groupId"
          placeholder="请选择交易状态"
          clearable
          class="!w-280px"
        >
          <el-option v-for="group in []" :key="group.id" :label="group.name" :value="group.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单号">
        <el-input
          v-show="true"
          v-model="queryParams[queryType.queryParam]"
          :type="queryType.queryParam === 'userId' ? 'number' : 'text'"
          class="!w-280px"
          clearable
          placeholder="请输入"
        >
          <template #prepend>
            <el-select
              v-model="queryType.queryParam"
              class="!w-110px"
              clearable
              placeholder="全部"
              @change="inputChangeSelect"
            >
              <el-option
                v-for="dict in dynamicSearchList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          v-model="queryParams.createTime"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-280px"
          end-placeholder="自定义时间"
          start-placeholder="自定义时间"
          type="daterange"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery">
          <Icon class="mr-5px" icon="ep:search" />
          搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon class="mr-5px" icon="ep:refresh" />
          重置
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <PureTableBar title="" :columns="columns" @refresh="handleQuery">
      <template #title>
        <el-text
          >总订单数：100笔 总订单金额：5000元 总交易手续费：50元 成功交易总金额：1000元
          退款交易总金额：50元</el-text
        >
      </template>
      <template #default="{ size, dynamicColumns }">
        <pure-table
          ref="tableRef"
          row-key="id"
          align-whole="center"
          :loading="loading"
          :size="size"
          :data="list"
          :columns="dynamicColumns"
        >
          <template #sex="scope">
            <dict-text :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
          </template>
          <template #empty>
            <Empty />
          </template>
        </pure-table>

        <Pagination
          v-model:limit="queryParams.pageSize"
          v-model:page="queryParams.pageNo"
          :total="total"
          @pagination="getList"
        />
      </template>
    </PureTableBar>
    <!-- 分页 -->
  </ContentWrap>
</template>
<script lang="ts" setup>
import * as UserApi from '@/api/member/user'

import { DICT_TYPE } from '@/utils/dict'

defineOptions({ name: 'MemberUser' })
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据

import { PureTableBar } from '@/components/RePureTableBar'

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  nickname: null,
  mobile: null,
  loginDate: [],
  createTime: [],
  tagIds: [],
  levelId: null,
  groupId: null
})
const queryFormRef = ref() // 搜索的表单

const tableRef = ref()
import { useUser } from './utils/hook'
const { columns } = useUser()
const queryType = reactive({ queryParam: '' }) // 订单搜索类型 queryParam
// 订单聚合搜索 select 类型配置（动态搜索）
const dynamicSearchList = ref([
  { value: 'no', label: '平台订单号' },
  { value: 'userId', label: '商户订单' },
  { value: 'userNickname', label: '支付流水' },
  { value: 'userMobile', label: '商户销售订单' }
])
/**
 * 聚合搜索切换查询对象时触发
 * @param val
 */
const inputChangeSelect = (val: string) => {
  dynamicSearchList.value
    .filter((item) => item.value !== val)
    ?.forEach((item1) => {
      // 清除集合搜索无用属性
      if (queryParams.hasOwnProperty(item1.value)) {
        delete queryParams[item1.value]
      }
    })
}
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    // const data = await UserApi.getUserPage(queryParams)

    // list.value = data.list
    // total.value = data.total
    list.value = []
    total.value = 0
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetprops()
  handleQuery()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
